<html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta content="text/javascript" http-equiv="content-script-type">
<title>tango.io.FileConduit</title>

<link rel="stylesheet" type="text/css" href="css/style.css">
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="css/ie56hack.css"><![endif]-->
<script language="JavaScript" src="js/util.js" type="text/javascript"></script>
<script language="JavaScript" src="js/tree.js" type="text/javascript"></script>
<script language="JavaScript" src="js/explorer.js" type="text/javascript"></script>
<script>
function anchorFromTitle(title, path, ext) {
  var url = path + title + "." + ext;
  document.write("<a href='" + url + "'>" + title + "</a>");
  }
</script>
</head><body>
<div id="tabarea"></div><div id="explorerclient"></div>
<div id="content"><script>explorer.initialize("tango.io.FileConduit");</script>
        <table class="content">
                <tr><td id="docbody"><h1><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791">tango.io.FileConduit</a></h1>
                
<b>License:</b><br>
BSD style: see <a href="http://www.dsource.org/projects/tango/wiki/LibraryLicense">license.txt</a><br><br>
<b>Version:</b><br>
Initial release: March 2004      
                        Outback release: December 2006<br><br>
<b>author:</b><br><ul>Kris</ul>
                        <ul>John Reimer</ul>
                        <ul>Anders F Bjorklund (Darwin patches)</ul>
                        <ul>Chris Sauls (Win95 file support)</ul><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>class <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L121">FileConduit</a></span>
<script>explorer.outline.addDecl('FileConduit');</script> : DeviceConduit, DeviceConduit.Seek;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Implements a means of reading and writing a generic file. Conduits
        are the primary means of accessing external data and FileConduit
        extends the basic pattern by providing file-specific methods to
        set the file size, seek to a specific file position and so on. 
        
        Serial input and output is straightforward. In this example we
        copy a file directly to the console:
        <pre class="d_code">

        <span class="lc">// open a file for reading</span>
        <span class="k">auto</span> <span class="i">from</span> = <span class="k">new</span> <span class="i">FileConduit</span> (<span class="sl">"test.txt"</span>);

        <span class="lc">// stream directly to console</span>
        <span class="i">Stdout</span>.<span class="i">copy</span> (<span class="i">from</span>);
        
</pre></font><br><br>
<font color="black">And here we copy one file to another:
        <pre class="d_code">

        <span class="lc">// open another for writing</span>
        <span class="k">auto</span> <span class="i">to</span> = <span class="k">new</span> <span class="i">FileConduit</span> (<span class="sl">"copy.txt"</span>, <span class="i">FileConduit</span>.<span class="i">WriteCreate</span>);

        <span class="lc">// copy file</span>
        <span class="i">to</span>.<span class="i">output</span>.<span class="i">copy</span> (<span class="k">new</span> <span class="i">FileConduit</span>(<span class="sl">"test.txt"</span>));
        
</pre>
        
        To load a file directly into memory one might do this:
        <pre class="d_code">

        <span class="lc">// open file for reading</span>
        <span class="k">auto</span> <span class="i">fc</span> = <span class="k">new</span> <span class="i">FileConduit</span> (<span class="sl">"test.txt"</span>);

        <span class="lc">// create an array to house the entire file</span>
        <span class="k">auto</span> <span class="i">content</span> = <span class="k">new</span> <span class="k">char</span>[<span class="i">fc</span>.<span class="i">length</span>];

        <span class="lc">// read the file content. Return value is the number of bytes read</span>
        <span class="k">auto</span> <span class="i">bytesRead</span> = <span class="i">fc</span>.<span class="i">input</span>.<span class="i">read</span> (<span class="i">content</span>);
        
</pre><br><br>        Conversely, one may write directly to a FileConduit, like so:
        <pre class="d_code">

        <span class="lc">// open file for writing</span>
        <span class="k">auto</span> <span class="i">to</span> = <span class="k">new</span> <span class="i">FileConduit</span> (<span class="sl">"text.txt"</span>, <span class="i">FileConduit</span>.<span class="i">WriteCreate</span>);

        <span class="lc">// write an array of content to it</span>
        <span class="k">auto</span> <span class="i">bytesWritten</span> = <span class="i">to</span>.<span class="i">output</span>.<span class="i">write</span> (<span class="i">content</span>);
        
</pre><br><br>        FileConduit can just as easily handle random IO. Here we use seek&#40;&#41;
        to relocate the file pointer and, for variation, apply a protocol to
        perform simple input and output:
        <pre class="d_code">

        <span class="lc">// open a file for reading</span>
        <span class="k">auto</span> <span class="i">fc</span> = <span class="k">new</span> <span class="i">FileConduit</span> (<span class="sl">"random.bin"</span>, <span class="i">FileConduit</span>.<span class="i">ReadWriteCreate</span>);

        <span class="lc">// construct (binary) reader &amp; writer upon this conduit</span>
        <span class="k">auto</span> <span class="i">read</span> = <span class="k">new</span> <span class="i">Reader</span> (<span class="i">fc</span>);
        <span class="k">auto</span> <span class="i">write</span> = <span class="k">new</span> <span class="i">Writer</span> (<span class="i">fc</span>);

        <span class="k">int</span> <span class="i">x</span>=<span class="n">10</span>, <span class="i">y</span>=<span class="n">20</span>;

        <span class="lc">// write some data, and flush output since protocol IO is buffered</span>
        <span class="i">write</span> (<span class="i">x</span>) (<span class="i">y</span>) ();

        <span class="lc">// rewind to file start</span>
        <span class="i">fc</span>.<span class="i">seek</span> (<span class="n">0</span>);

        <span class="lc">// read data back again</span>
        <span class="i">read</span> (<span class="i">x</span>) (<span class="i">y</span>);

        <span class="i">fc</span>.<span class="i">close</span>();
        
</pre><br><br>        See File, FilePath, FileScan, and FileSystem for 
        additional functionality related to file manipulation. <br><br>        Compile with -version=Win32SansUnicode to enable Win95 &amp; Win32s file 
        support.
        
</font><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>struct <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L129">Style</a></span>
<script>explorer.outline.addDecl('Style');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Fits into 32 bits ...</font><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Access <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L133">access</a></span>
<script>explorer.outline.addDecl('access');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">access rights</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Open <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L134">open</a></span>
<script>explorer.outline.addDecl('open');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">how to open</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Share <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L135">share</a></span>
<script>explorer.outline.addDecl('share');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">how to share</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Cache <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L136">cache</a></span>
<script>explorer.outline.addDecl('cache');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">how to cache</font><br><br></dd></dl></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>enum <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L143">Access</a></span>
<script>explorer.outline.addDecl('Access');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L144">Read</a></span>
<script>explorer.outline.addDecl('Read');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">is readable</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L145">Write</a></span>
<script>explorer.outline.addDecl('Write');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">is writable</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L146">ReadWrite</a></span>
<script>explorer.outline.addDecl('ReadWrite');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">both</font><br><br></dd></dl></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>enum <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L153">Open</a></span>
<script>explorer.outline.addDecl('Open');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L154">Exists</a></span>
<script>explorer.outline.addDecl('Exists');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">must exist</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L155">Create</a></span>
<script>explorer.outline.addDecl('Create');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">create or truncate</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L156">Sedate</a></span>
<script>explorer.outline.addDecl('Sedate');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">create if necessary</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L157">Append</a></span>
<script>explorer.outline.addDecl('Append');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">create if necessary</font><br><br></dd></dl></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>enum <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L164">Share</a></span>
<script>explorer.outline.addDecl('Share');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L165">None</a></span>
<script>explorer.outline.addDecl('None');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">no sharing</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L166">Read</a></span>
<script>explorer.outline.addDecl('Read');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">shared reading</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L167">ReadWrite</a></span>
<script>explorer.outline.addDecl('ReadWrite');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">open for anything</font><br><br></dd></dl></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>enum <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L174">Cache</a></span>
<script>explorer.outline.addDecl('Cache');</script>;</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black"></font><br><br>
<dl>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L175">None</a></span>
<script>explorer.outline.addDecl('None');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">don't optimize</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L176">Random</a></span>
<script>explorer.outline.addDecl('Random');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">optimize for random</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L177">Stream</a></span>
<script>explorer.outline.addDecl('Stream');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">optimize for stream</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L178">WriteThru</a></span>
<script>explorer.outline.addDecl('WriteThru');</script></li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">backing-cache flag</font><br><br></dd></dl></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L187">ReadExisting</a></span>
<script>explorer.outline.addDecl('ReadExisting');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Read an existing file
        
</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L195">WriteExisting</a></span>
<script>explorer.outline.addDecl('WriteExisting');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Write on an existing file. Do not create</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L203">WriteCreate</a></span>
<script>explorer.outline.addDecl('WriteCreate');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Write on a clean file. Create if necessary</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L211">WriteAppending</a></span>
<script>explorer.outline.addDecl('WriteAppending');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Write at the end of the file</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L219">ReadWriteExisting</a></span>
<script>explorer.outline.addDecl('ReadWriteExisting');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Read and write an existing file</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L227">ReadWriteCreate</a></span>
<script>explorer.outline.addDecl('ReadWriteCreate');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Read &amp; write on a clean file. Create if necessary</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L235">ReadWriteOpen</a></span>
<script>explorer.outline.addDecl('ReadWriteOpen');</script>; [const]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Read and Write. Use existing file if present</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L252">this</a></span>
<script>explorer.outline.addDecl('this');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Create a FileConduit for use with open&#40;&#41;</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L262">this</a></span>
<script>explorer.outline.addDecl('this');</script>(char[] <span class="funcparam">path</span>, Style <span class="funcparam">style</span> = ReadExisting);</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Create a FileConduit with the provided path and style.</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li><span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L275">this</a></span>
<script>explorer.outline.addDecl('this');</script>(PathView <span class="funcparam">path</span>, Style <span class="funcparam">style</span> = ReadExisting); [deprecated]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Create a FileConduit with the provided path and style.</font><br><br>
<font color="red">Deprecated:</font><br>
use char[] ctor instead<br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>PathView <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L288">path</a></span>
<script>explorer.outline.addDecl('path');</script>(); [deprecated]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Return the PathView used by this file.</font><br><br>
<font color="black">We're removing PathView here, in favour of toString&#40;&#41;<br><br></font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>Style <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L300">style</a></span>
<script>explorer.outline.addDecl('style');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Return the Style used for this file.</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>char[] <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L311">toString</a></span>
<script>explorer.outline.addDecl('toString');</script>(); [override]</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Return the name of the FilePath used by this file.</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>long <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L322">position</a></span>
<script>explorer.outline.addDecl('position');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Return the current file position.
                
</font><br><br></dd>
<script>explorer.outline.writeEnabled = true;</script>
<dt><span class="decl"><li>long <span class="currsymbol"><a href="http://www.dsource.org/projects/tango/browser/trunk/tango/io/FileConduit.d?rev=3791#L333">length</a></span>
<script>explorer.outline.addDecl('length');</script>();</li></span></dt>
<script>explorer.outline.writeEnabled = false;</script>
<dd>
<font color="black">Return the total length of this file.</font><br><br></dd></dl></dd></dl></td></tr>
                <tr><td id="docfooter">
                        Copyright (c) 2004 Kris Bell. All rights reserved :: page rendered by CandyDoc. Generated by <a href="http://code.google.com/p/dil">dil</a> on Sat Aug  2 16:08:34 2008.
                </td></tr>
        </table>
</div>
<script></script>
</body></html>